package org.lee.currentdate;

import java.text.SimpleDateFormat;
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * CurrentDateDemo
 * 获取当前时间方式
 *
 * @author dralee
 * @date 2021-12-29 18:37:28
 **/
public class CurrentDateDemo {

    public static void main(String[] args) {
        // 当前时间  2021-12-29T10:30:35.742Z
        Instant instant = Instant.now();
        System.out.println(instant);

        // 当前时间
        LocalDateTime now = LocalDateTime.now();
        System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(now));

        // 当前时间
        ZonedDateTime zNow = ZonedDateTime.now();
        System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(zNow));

        // 当前时间 2021-12-29T10:33:13.815Z
        Clock clock = Clock.systemDefaultZone();
        Instant cNow = clock.instant();
        System.out.println(cNow);

        // 当前时间
        Date dNow = new Date();
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dNow));

        // 当前时间
        Date cdNow = Calendar.getInstance().getTime();
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cdNow));

        // 当前时间
        org.joda.time.LocalDateTime ldt = new org.joda.time.LocalDateTime();
        org.joda.time.format.DateTimeFormatter dFormat = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        String str = dFormat.print(ldt);
        System.out.println(str);

        // 当前时间
        org.joda.time.format.DateTimeFormatter tFormat = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        String str1 = tFormat.print(org.joda.time.DateTime.now());
        System.out.println(str1);
    }
}
